<template>
	<view class="order-page">
		<view class="goods-info">
			<image class="image" :src="goodsInfo.img.url" mode="aspectFill"></image>
			<view class="content">
				<view class="title">{{ goodsInfo.name }}</view>
				<view class="price">￥{{ goodsInfo.price }}</view>
				<view class="bottom">
					<view class="specs">规格：一份</view>
					<view class="num">x1</view>
				</view>
			</view>
		</view>
		<view class="info-box">
			<view class="top">
				<view class="label">商品金额</view>
				<view class="price">￥{{ goodsInfo.price }}</view>
			</view>
			<view class="bottom">
				<view class="item">
					<text class="text">已优惠</text>
					<text class="value">￥0.00</text>
				</view>
				<view class="item">
					<text class="text">剩余应付</text>
					<text class="value">￥{{ goodsInfo.price }}</text>
				</view>
			</view>
		</view>
		
		<view class="bottom-box">
			<view class="price">合计:￥{{ goodsInfo.price }}</view>
			<button class="btn" size="mini" @click="pay">提交订单</button>
		</view>
	</view>
</template>

<script>
	import { confirmOrder, getMaterial } from '@/api/api'

	export default {
		data () {
			return {
				goodsInfo: {},
			}
		},
		onLoad () {
			const eventChannel = this.getOpenerEventChannel()
			eventChannel.on('onOrder', (data) => {
				this.goodsInfo = data
			})
		},
		methods: {
			pay () {
				uni.showLoading({ mask: true })
				
				confirmOrder({
					sku_details: [{
						note: '',
						num: 1,
						goods_item_id: this.goodsInfo.skuInfo.id
					}],
					integral: 0,
					goods_type: 1
				}).then(res => {
					uni.hideLoading({ noConflict: true })
				
					if (res) {
						const data = res.data
						
						uni.redirectTo({
							url: `/pages/index/cash?total_amount=${data.total_amount}&trade_sn=${data.trade_sn}&type=code`
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss">
.order-page {
	box-sizing: border-box;
	padding: 24rpx;
	min-height: 100%;
	background-color: $bg-color;
	.goods-info {
		padding: 28rpx;
		border-radius: 14rpx;
		background-color: #fff;
		display: flex;
		.image {
			width: 180rpx;
			height: 180rpx;
			border-radius: 8rpx;
		}
		.content {
			flex: 1;
			margin-left: 30rpx;
			display: flex;
			flex-direction: column;
			.title {
				color: #333333;
				font-size: 30rpx;
			}
			.price {
				margin-top: auto;
				color: #666;
				font-size: 24rpx;
			}
			.bottom {
				margin-top: auto;
				display: flex;
				align-items: center;
				justify-content: space-between;
				.specs {
					color: #6c6c6c;
					font-size: 28rpx;
				}
				.num {
					color: #333333;
					font-size: 24rpx;
				}
			}
		}
	}
	.info-box {
		margin-top: 24rpx;
		padding: 0 28rpx;
		border-radius: 14rpx;
		background-color: #fff;
		.top {
			padding: 32rpx 0 54rpx;
			border-bottom: 1rpx solid #eee;
			color: #3a3a3a;
			font-size: 28rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
		}
		.bottom {
			padding: 54rpx 0 32rpx;
			color: #333;
			font-size: 26rpx;
			display: flex;
			align-items: center;
			justify-content: flex-end;
			gap: 72rpx;
			.value {
				color: #cd2a1b;
			}
		}
	}
	.bottom-box {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		z-index: 10;
		height: 100rpx;
		padding: 0 28rpx;
		padding-bottom: 0;
		padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: env(safe-area-inset-bottom);
		background-color: #fff;
		display: flex;
		align-items: center;
		justify-content: space-between;
		.price {
			color: #000;
			font-size: 32rpx;
		}
		.btn {
			margin: 0;
			padding: 0;
			border-radius: 72rpx;
			width: 200rpx;
			height: 72rpx;
			color: #fff;
			font-size: 30rpx;
			line-height: 72rpx;
			background-color: #cd2a1b;
		}
	}
}
</style>
